import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
public class TicketTest {
    private Ticket ticket;
    private Screening screening;
    private Seat seat;
    @BeforeEach
    void setUp() {
        // 初始化 Screening 对象
        screening = new Screening("screen001", new Movie("movie001", "Test Movie", "Director", "Actors","Intro",100,7.5),"1号厅", new Date(),50);
        // 初始化 Seat 对象
        seat = new Seat(1, 1);
        // 初始化 Ticket 对象
        ticket = new Ticket("TICKET-123", screening, new ArrayList<>(), 100.0, new Date(), 2, 200.0, 0, 0.0);
    }
    // 测试构造方法赋值是否正确
    @Test
    void testConstructor() {
        assertEquals("TICKET-123", ticket.getTicketId());
        assertEquals(screening, ticket.getScreening());
        assertEquals(100.0, ticket.getTotalPrice());
        assertNotNull(ticket.getBuyTime());
        assertEquals(2, ticket.getTotalTickets());
        assertEquals(200.0, ticket.getTotalAmount());
        assertEquals(0, ticket.getRefundTickets());
        assertEquals(0.0, ticket.getRefundAmount());
        assertFalse(ticket.isRefunded());
    }
    // 测试售票方法
    @Test
    void testSell() {
        ticket.sell(3, 50.0);
        assertEquals(5, ticket.getTotalTickets());
        assertEquals(200.0 + 3 * 50.0, ticket.getTotalAmount());
    }
    // 测试添加座位方法
    @Test
    void testAddSeat() {
        ticket.addSeat(seat);
        assertEquals(1, ticket.getSeats().size());
        assertTrue(ticket.getSeats().contains(seat));
    }
    // 测试退票标记方法
    @Test
    void testRefund() {
        ticket.refund();
        assertTrue(ticket.isRefunded());
    }
    // 测试设置购买时间方法
    @Test
    void testSetBuyTime() {
        Date newBuyTime = new Date();
        ticket.setBuyTime(newBuyTime);
        assertEquals(newBuyTime, ticket.getBuyTime());
    }
    // 测试获取总票数、总金额等 getter 方法
    @Test
    void testGetters() {
        assertEquals(2, ticket.getTotalTickets());
        assertEquals(200.0, ticket.getTotalAmount());
        assertEquals(0, ticket.getRefundTickets());
        assertEquals(0.0, ticket.getRefundAmount());
        assertEquals("TICKET-123", ticket.getTicketId());
        assertEquals(screening, ticket.getScreening());
        assertEquals(new ArrayList<>(), ticket.getSeats());
        assertEquals(screening, ticket.getScreening());
        assertNotNull(ticket.getBuyTime());
    }
    // 测试设置退票票数、金额等 setter 方法
    @Test
    void testSetters() {
        ticket.setRefundTickets(1);
        assertEquals(1, ticket.getRefundTickets());
        ticket.setRefundAmount(50.0);
        assertEquals(50.0, ticket.getRefundAmount());
        // 其他 setter 方法可类似测试
        ticket.setTotalTickets(5);
        assertEquals(5, ticket.getTotalTickets());
    }
    // 测试退票方法
    @Test
    void testRefundWithParams() {
        ticket.refund(2, 100.0);
        assertFalse(ticket.isRefunded());
        assertEquals(2, ticket.getRefundTickets());
        assertEquals(100.0, ticket.getRefundAmount());
    }
}

